package com.vitabuybuy.tv.ui.mine.talent.usercenter

import android.os.Bundle
import androidx.core.os.bundleOf
import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter
import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ActivityLiveIncomeRecordBinding
import com.library.common.base.BaseActivity
import com.library.common.base.MessageModel
import com.vitabuybuy.tv.ui.mine.talent.usercenter.viewmodel.LiveIncomeManageViewModel
import kotlinx.android.synthetic.main.activity_withdraw_account.*

class LiveIncomeRecordActivity :
    BaseActivity<LiveIncomeManageViewModel, ActivityLiveIncomeRecordBinding>() {
    override val isUseBaseTitleBar: Boolean
        get() = true
    override val layoutId: Int
        get() = R.layout.activity_live_income_record

    private var type :String?= ""
    private var pageNumber = 1

    override fun onGetBundle(bundle: Bundle?) {
        type = bundle?.getString("type")
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitle(if (type == "收入") getString(R.string.income_record_2) else getString(R.string.exchange_record))
        mBinding.mViewModel = viewModel
    }

    override fun observeData() {
        viewModel.getData(type, pageNumber)
    }
    override fun eventHandling() {
        refresh.setOnRefreshListener(object : RefreshListenerAdapter() {
            override fun onLoadMore(refreshLayout: TwinklingRefreshLayout?) {
                pageNumber++
                viewModel.getData(type, pageNumber)
            }

            override fun onRefresh(refreshLayout: TwinklingRefreshLayout?) {
                pageNumber = 1
                viewModel.getData(type, pageNumber)
            }
        })
    }

    override fun handleEvent(msg: MessageModel) {
        when (msg.code) {
            0 -> {
                pageNumber = 1
                viewModel.getData(type, pageNumber)
            }
            1 -> {
                refresh.onLoad(msg.code)
            }
        }
    }

    companion object {
        fun openActivity(mContext: BaseActivity<*, *>, type: String) {
            mContext.startActivity(
                bundleOf(Pair("type", type)),
                LiveIncomeRecordActivity::class.java
            )
        }
    }
}
